/*
 * InputManager.h
 *
 *  Created on: 18.11.2009
 *      Author: Sergej Schmidt
 */

#ifndef INPUTMANAGER_H_
#define INPUTMANAGER_H_

#include <Ogre.h>
#include <OIS.h>

class InputManager  : public OIS::KeyListener, OIS::MouseListener, OIS::JoyStickListener
{
public:
	virtual ~InputManager();

	void initialise( Ogre::RenderWindow* renderWindow );
	void capture( void );

	void addKeyListener( OIS::KeyListener* keyListener, const std::string& instanceName );
	void addMouseListener( OIS::MouseListener* mouseListener, const std::string& instanceName );
	void addJoystickListener( OIS::JoyStickListener* joystickListener, const std::string& instanceName );

	void removeKeyListener( const std::string& instanceName );
	void removeMouseListener( const std::string& instanceName );
	void removeJoystickListener( const std::string& instanceName);

    void removeKeyListener( OIS::KeyListener *keyListener );
    void removeMouseListener( OIS::MouseListener *mouseListener );
    void removeJoystickListener( OIS::JoyStickListener *joystickListener );

	void removeAllListeners(void);
	void removeAllKeyListeners(void);
	void removeAllMouseListeners(void);
	void removeAllJoystickListeners(void);

	void setWindowExtents( int width, int height );

	OIS::Keyboard*	getKeyboard(void);
	OIS::Mouse*		getMouse(void);
	OIS::JoyStick*	getJoystick( unsigned int index );

	int getNumOfJoysticks(void);

	static InputManager* getSingletonPtr( void );
private:
	InputManager();
	InputManager( const InputManager& ) { }
	InputManager & operator = ( const InputManager& );

	bool keyPressed( const OIS::KeyEvent& e );
	bool keyReleased( const OIS::KeyEvent& e );

	bool mouseMoved( const OIS::MouseEvent& e );
	bool mousePressed( const OIS::MouseEvent& e, OIS::MouseButtonID id );
	bool mouseReleased( const OIS::MouseEvent& e, OIS::MouseButtonID id );

    bool povMoved( const OIS::JoyStickEvent& e, int pov );
    bool axisMoved( const OIS::JoyStickEvent& e, int axis );
    bool sliderMoved( const OIS::JoyStickEvent& e, int sliderID );
    bool buttonPressed( const OIS::JoyStickEvent& e, int button );
    bool buttonReleased( const OIS::JoyStickEvent& e, int button );

    OIS::InputManager*	m_pInputSystem;
    OIS::Keyboard*		m_pKeyboard;
    OIS::Mouse*			m_pMouse;

    std::vector<OIS::JoyStick*> m_vecJoysticks;
    std::vector<OIS::JoyStick*>::iterator itJoystick;
    std::vector<OIS::JoyStick*>::iterator itJoystickEnd;

    std::map<std::string, OIS::KeyListener*> m_mapKeyListeners;
    std::map<std::string, OIS::MouseListener*> m_mapMouseListeners;
    std::map<std::string, OIS::JoyStickListener*> m_mapJoystickListeners;

    std::map<std::string, OIS::KeyListener*>::iterator itKeyListener;
    std::map<std::string, OIS::MouseListener*>::iterator itMouseListener;
    std::map<std::string, OIS::JoyStickListener*>::iterator itJoystickListener;

    std::map<std::string, OIS::KeyListener*>::iterator itKeyListenerEnd;
    std::map<std::string, OIS::MouseListener*>::iterator itMouseListenerEnd;
    std::map<std::string, OIS::JoyStickListener*>::iterator itJoystickListenerEnd;

    static InputManager *m_pInputManager;
};
#endif /* INPUTMANAGER_H_ */
